package com.wu;

import java.util.Iterator;

/**
 * @description: <br>
 * @date: 2020/6/15 <br>
 * @author: fei.wu <br>
 */

public class Context {

    private Iterator<Rule> ruleIterator;

    private Integer initPrice;

    public Context(Iterator<Rule> ruleIterator,Integer initPrice) {
        super();
        this.initPrice = initPrice;
        this.ruleIterator = ruleIterator;
    }

    public Integer invokeNext(Integer price){
        if (price == null){
            price = initPrice;
        }
        if(ruleIterator.hasNext() ){
            price = ruleIterator.next().invoke( this ,price);
        }
        return price;
    }
}
